package com.ltkj.baseplatform.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.baseplatform.domain.SerAddressArea;
import com.ltkj.baseplatform.service.ISerAddressAreaService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;

/**
 * 收货地址区域Controller
 * 
 * @author chenzeen
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/area")
@Api(tags = "收货地址区域")
public class SerAddressAreaController extends BaseController
{
    @Autowired
    private ISerAddressAreaService serAddressAreaService;

    /**
     * 查询收货地址区域列表
     */
    @RequiresPermissions("baseplatform:area:list")
    @GetMapping("/list")
    @ApiOperation("查询收货地址区域列表")
    public AjaxResult list(SerAddressArea serAddressArea)
    {
        List<SerAddressArea> list = serAddressAreaService.selectSerAddressAreaList(serAddressArea);
        return success(list);
    }

    /**
     * 导出收货地址区域列表
     */
    @RequiresPermissions("baseplatform:area:export")
    @Log(title = "收货地址区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SerAddressArea serAddressArea)
    {
        List<SerAddressArea> list = serAddressAreaService.selectSerAddressAreaList(serAddressArea);
        ExcelUtil<SerAddressArea> util = new ExcelUtil<SerAddressArea>(SerAddressArea.class);
        util.exportExcel(response, list, "收货地址区域数据");
    }

    /**
     * 获取收货地址区域详细信息
     */
    @RequiresPermissions("baseplatform:area:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取收货地址区域详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serAddressAreaService.selectSerAddressAreaById(id));
    }

    /**
     * 新增收货地址区域
     */
    @RequiresPermissions("baseplatform:area:add")
    @Log(title = "收货地址区域", businessType = BusinessType.INSERT)
    @ApiOperation("新增收货地址区域")
    @PostMapping
    public AjaxResult add(@RequestBody SerAddressArea serAddressArea)
    {
        return toAjax(serAddressAreaService.insertSerAddressArea(serAddressArea));
    }

    /**
     * 修改收货地址区域
     */
    @RequiresPermissions("baseplatform:area:edit")
    @Log(title = "收货地址区域", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改收货地址区域")
    public AjaxResult edit(@RequestBody SerAddressArea serAddressArea)
    {
        return toAjax(serAddressAreaService.updateSerAddressArea(serAddressArea));
    }

    /**
     * 删除收货地址区域
     */
    @RequiresPermissions("baseplatform:area:remove")
    @Log(title = "收货地址区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除收货地址区域")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serAddressAreaService.deleteSerAddressAreaByIds(ids));
    }

    /**
     * 获取初次选择数据
     * @return
     */
    @GetMapping("/getInitData")
    @ApiOperation("获取初次选择数据")
    public AjaxResult getInitData(){
        return success(serAddressAreaService.getInitData());
    }

    /**
     * 根据区域code获取下级区域
     * @return
     */
    @GetMapping("/getNextAreaByCode")
    @ApiOperation("根据区域code获取下级区域")
    public AjaxResult getNextAreaByCode(String areaCode){
        return success(serAddressAreaService.getNextAreaByCode(areaCode));
    }
}
